// subpkg/movie-detail/movie-detail.js
import { getMovieDetail } from '../../api/movie-maoyan'
Page({
  data: {
    movieDetail: {},
    isOpen: false // 是否展开
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getMovieDetailData(options.id)
  },
  async getMovieDetailData(movieId) {
    const res = await getMovieDetail(movieId)

    this.setData({
      movieDetail: res.detailMovie
    }, () => {
      wx.setNavigationBarTitle({
        title: res.detailMovie.nm,
      })
    })
  },
  openOrFold() {
    this.setData({
      isOpen: !this.data.isOpen
    })
  },
  onShareAppMessage() {
    return {
      title: this.data.movieDetail.movie.nm,
      imageUrl: this.data.movieDetail.movie.img,
      path: `/pages/index/index`,
      query: `id=${this.data.movieDetail.movie.id}`
    }
  },
  onShareTimeline() {
    return {
      title: this.data.movieDetail.movie.nm,
      imageUrl: this.data.movieDetail.movie.img, // 图片 URL
      query: 'a=1&b=2'
    }
  },
  // 去购票
  purchaseTicket() {
    wx.navigateTo({
      url: `/subpkg/purchase/purchase?movieId=${this.data.movieDetail.id}&cityId=30`,
    })
  }
})